package com.marver.login.service;

import com.marver.beans.request.LoginReq;
import com.marver.beans.response.UserInfoVo;
import com.marver.common.dao.BaseDAOImpl;
import com.marver.common.enumeration.LabeledEnumResolver;
import com.marver.common.result.Result;
import com.marver.common.result.ResultStatus;
import com.marver.common.utils.MD5Util;
import com.marver.entity.AdminUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class AccountService extends BaseDAOImpl {
	private Logger logger =LoggerFactory.getLogger(AccountService.class);
    @Autowired
    private LabeledEnumResolver labeledEnumResolver;
    
    @Value("${web.upload-path}")
    private String webUploadPath;
     
    /**
     * 获取当前登录用户详细信息
     * @param adminUser
     * @return
     */
	public Result queryCurrUser(AdminUser adminUser){
		List<UserInfoVo> list=new ArrayList<UserInfoVo>();
		UserInfoVo userInfo=new UserInfoVo();//(UserInfoVo)this.findObjectBySqlMap("account.getAccounts", account);
		BeanUtils.copyProperties(adminUser, userInfo);
		userInfo.setState(labeledEnumResolver.getStringLabeledEnum(String.valueOf(adminUser.getState())));
		userInfo.setUserType(labeledEnumResolver.getStringLabeledEnum(adminUser.getUserType()));
		list.add(userInfo);
		return new Result(ResultStatus.SUCCESS.getErrorCode(),list);
	}
	
	/**
	 * 修改密码
	 * @return
	 */
	public Result changePwd(LoginReq loginPara){
		String password=MD5Util.createMD5Util().getMD5String(loginPara.getPassword());
		loginPara.setPassword(password);
		this.updateBySqlMap("account.changePwdByTelNum", loginPara);
		return  new Result(ResultStatus.SUCCESS.getErrorCode());
	}
	
}
